// do /Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Code/T_C1_SumStats_Choice_Set_Demo.do

/*
This script creates Table 1 : summary statistics for the choice set, which has variations across all dimensions
*/

clear all
set more off
set maxvar 15000
set matsize 9000
pause on

//Sebastien's server
global  pathname 	= "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Data"
global  pathresults = "/Users/shoude/Dropbox/eegap/EEgap_data_code_heter_SM/Results"


//Check
//use $pathname\refrigerators\lcidemo_046_2007_2012_Dhd_week_store_ts_cleaned, clear

//use "$pathname/lcidemo_046_2008_2012_struct_v11_11022017_robustb_nocensor_11022017", clear

use "$pathname/lcidemo_046_2007_2012_Dhd_week_store_ts_cleaned", clear


//---------------------------------------------------------------
// Bring local electricity prices: state and county
//---------------------------------------------------------------

sort state year
merge state year using $pathname/electricity_price_state_2007_2012
tab _m
tab state if _m==1
tab year if _m==1
drop if _m==2
drop _m

sort zipcode
merge zipcode using $pathname/mapping_zip_county_nov99_short
tab _m
drop if _m==2
drop _m
ren county5 county_utility

//Electricity County	
sort county_utility year
merge county_utility year using $pathname/county_elec_price_2007_2012
tab _m
drop if _m==2
drop _m
replace pcount = p_elec if pcount==.

//In this paper: we use county-level electricity price
gen elec_cost = kwh*pcount/100

//---------------------------------------------------------------
//Rebates: utility and cash for appliances
//---------------------------------------------------------------
		sort state week
 		sort county_utility year week
		merge county_utility year week using "$pathname/DSIRE_rebate_week_county_2007_2013"  
		tab _m
		drop if _m==2
		drop _m
		ren incentive incentive_utility
		mvencode incentive_utility,mv(0) over 
		replace incentive_utility=incentive_utility/100
		
		sort week state year
		merge  week state  year using  "$pathname/cash4appliance_refrigerators_weekly_vf"
		tab _m
		drop if _m==2	
		ren _m merge_rebate
		replace incentive=0 if merge_rebate==1
		//incentive is in ,00$
		replace incentive=incentive/100

		gen rebate_es = incentive_utility + incentive
//---------------------------------------------------------------
// Generate demographic information
//---------------------------------------------------------------
         
xtile age_gr = age, n(4)

gen fam_size = adult+children

gen income_sub1 = cond(income_sub==35, 1, 0)
gen income_sub2 = cond(income_sub==45, 1, 0)
gen income_sub3 = cond(income_sub==55, 1, 0)

//---------------------------------------------------------------
// Table 1: Sum stats for main attributes and demographics
//---------------------------------------------------------------
preserve
gen Dsize     = cond(AV<29,1,0)
gen Dtop      = cond(type_id ==1,1,0)
gen promo_tax = promo +tax/o_qty


sum promo_p
sum kwh
sum pcount
sum p_elec
sum elec_cost
sum rebate_es
sum rebate_es if rebate_es>0
sum estar
sum AV
sum Dtop
sum ice

sum Dhd	
sum rent
sum miss_demo
tab income
